<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="../../../common/include.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>修改费用预留发放信息</title>
<jsp:include page="../../../common/head.jsp">
	  <jsp:param name="_useCalendar" value="true"/>
</jsp:include>
<script language="javascript">
	function saveData(submitType){
		var objarr = new Array(
			["feeGrant.feeGrantCompanyName","费用单位名称","notEmpty",""],
			["feeGrant.feeGrantCompanyName","费用单位名称","max","String:50"],
			["feeGrant.areaId","地区","notEmpty",""],
			["feeGrant.areaDeptId","事业部","notEmpty",""],
			["feeGrant.feeGrantDate","预留发放日期","notEmpty",""],
			["feeGrant.feeGrantAmount","预留发放金额","notEmpty",""],
			["feeGrant.feeGrantAmount","预留发放金额","float","10.4"],
			["feeGrant.feeGrantRemark","备注","max","String:500"]
		);
		if(xj.CheckAll(objarr))
		{
			if(confirm("确认保存？"))
			{
				$("#submitType").val(submitType);
				if($("#feeGrantType").find("option:selected").val()=="发放")
				{
					var tmp = parseInt(Math.random()*10000000+1);//设定随机数防止浏览器以相同url重复多次访问不进行请求
					var url = "checkAmountFeeGrant.do?tmp="+tmp;
					$.ajax({
						type: "POST",
						url: url,
						data: $("#form1").serialize(),
						success: function(data,status){
							if(data!="ok")
							{
								alert("预留金额小于发放金额，当前余额("+data+")，请检查修改！");
								return;
							}
							else
								document.getElementById("form1").submit();
						}
					});
				}
				else
					document.getElementById("form1").submit();
			}
		}
	}
	//读取预留余额
	function readData(){
		
		var tmp = parseInt(Math.random()*10000000+1);//设定随机数防止浏览器以相同url重复多次访问不进行请求
		var url = "readAmountFeeGrant.do?tmp="+tmp;
		$.ajax({
			type: "POST",
			url: url,
			data: $("#form1").serialize(),
			success: function(data,status){
				$("#ylye").text(data);
			}
		});
	}
	//返回
	function goback()
	{
		window.top.close();
	}

	//将select的option的text放入hidden
	function selectOption(objSelect,hiddenId)
	{
		$("#"+hiddenId).val($(objSelect).find("option:selected").text());
		//地区变换变换费用类型
		if(hiddenId=="areaName")
		{
			selectFeeTarget();
		}
	}
</script>

</head>
<body>
<form name="form1" id="form1"  action="updateFeeGrant.do" method="post">
	<input type="hidden" id="submitType" name="submitType" value="save"/>
	<input type="hidden" id="feeGrantId" name="feeGrant.feeGrantId" value="${feeGrant.feeGrantId}"/>
	<input type="hidden" name="feeGrant.state" value="${feeGrant.state}"/>
	<input type="hidden" name="feeGrant.createUserId" value="${feeGrant.createUserId}"/>
	<input type="hidden" name="feeGrant.createUserName" value="${feeGrant.createUserName}"/>
	<w:select name="feeGrant.feeGrantType" styleId="feeGrantType" value="${feeGrant.feeGrantType}" style="display:none">
		<w:option optionLabel="发放" optionValue="发放"></w:option>
		<w:option optionLabel="预留" optionValue="预留"></w:option>
	</w:select>
	<div id="body_div">
	<w:ShowTitle name="修改费用预留发放信息" useSubmitKey="false">
	<w:TitleButton funcName="读取预留余额" onClickFunction="readData()" urlImg="${ctx}/images/main/update.png"/>
	<w:TitleButton funcName="保存并复制添加" onClickFunction="saveData('saveAndAdd')" urlImg="${ctx}/images/main/save.png"/>
	<w:TitleButton funcName="保存" onClickFunction="saveData('save')" urlImg="${ctx}/images/main/save.png"/>
	<w:TitleButton funcName="返回" onClickFunction="goback()" urlImg="${ctx}/images/main/back.png"/>
	</w:ShowTitle>
	<div id="body_content">
	<table width="100%">
            <tr>
              <td width="80" class="right_align">地区</td>
              <td width="230" class="left_align">
				<input type="hidden" id="areaName" name="feeGrant.areaName" value="${feeGrant.areaName}"/>
				<input type="text" class="selectValueFilter" style="${style}"/>
				<w:select name="feeGrant.areaId" styleId="areaId" value="${feeGrant.areaId}" onchange="selectOption(this,'areaName')" style="${style}">
					<w:option optionLabel="请选择" optionValue=""></w:option>
					<w:options options="${CodeDict}" optionLabel="codeName" optionValue="codeId" filterFieldName="parentCodeId" filterFieldValue="001"></w:options>
				</w:select>
			  </td>
              <td width="80" class="right_align">事业部</td>
              <td width="230" class="left_align">
				<input type="hidden" id="areaDeptName" name="feeGrant.areaDeptName" value="${feeGrant.areaDeptName}"/>
              	<input type="text" class="selectValueFilter" style="${style}"/>
              	<w:select name="feeGrant.areaDeptId" styleId="areaDeptId" value="${feeGrant.areaDeptId}" onchange="selectOption(this,'areaDeptName')" style="${style}">
					<w:option optionLabel="请选择" optionValue=""></w:option>
					<w:options options="${CodeDict}" optionLabel="codeName" optionValue="codeId" filterFieldName="parentCodeId" filterFieldValue="002"></w:options>
				</w:select>
			  </td>
              <td class="right_align" width="80">费用单位名称</td>
              <td class="left_align">
				<w:select name="feeGrant.feeGrantCompanyName" styleId="feeGrantCompanyName" value="${feeGrant.feeGrantCompanyName}">
					<w:option optionLabel="请选择" optionValue=""></w:option>
					<w:options options="${CodeDict}" optionLabel="codeName" optionValue="codeId" filterFieldName="parentCodeId" filterFieldValue="008"></w:options>
				</w:select>
              </td>
            </tr>
            <tr>
              <td class="right_align">预留余额</td>
              <td class="left_align" id="ylye">
              	
              </td>
              <td class="right_align">金额
              </td>
              <td class="left_align" id="targetIdTd">
              	<input type="text" name="feeGrant.feeGrantAmount" id="feeGrantAmount" value="${feeGrant.feeGrantAmount}"/>
              </td>
              <td class="right_align">费用日期</td>
              <td class="left_align">
				<input type="text" name="feeGrant.feeGrantDate" value="<fmt:formatDate value='${feeGrant.feeGrantDate}' pattern='yyyy-MM-dd' />" onfocus="new WdatePicker()" readonly="readonly" class="inputCal"/>
              </td>
            </tr>
            <tr>
              <td class="right_align">备注</td>
              <td colspan="5" class="left_align">
              	<textarea rows="5" cols="80" name="feeGrant.feeGrantRemark">${feeGrant.feeGrantRemark}</textarea>
              </td>
            </tr>
          </table>
	</div>
	</div>	
</form>
</body>
</html> 